using System;
using System.Collections.Generic;
using System.Web.Mvc;
using Machine.Specifications;
using Unbound.Tests.Unbinding.Configuration;

namespace Unbound.Tests.Unbinding.Specifications
{
	public abstract class unbinding<T>
	{
		protected static DefaultModelBinder Binder = new DefaultModelBinder();
		protected static object Bound;
		protected static Type ModelType = typeof (T);
		protected static string Prefix;
		protected static T Request;

		protected static Func<IDictionary<string, object>> Unbind =
			() => Request.ToHttpDictionary(Prefix);

		protected static IDictionary<string, object> Unbound;

		Because we_unbind_and_use_default_model_binder_to_reconstruct_the_object = () =>
		             	{
		             		Unbound = Unbind();
		             		var bindingContext = Unbound.BuildContext(ModelType, Prefix);
		             		Bound = Binder.BindModel(new ControllerContext(), bindingContext);
		             	};
	}
}